#!/usr/bin/python3
 
import pymongo
import datetime
import csv
 
# myclient = pymongo.MongoClient("mongodb://root:123456@192.168.200.109:27017/?replicaSet=rs0&authSource=admin") # 
myclient = pymongo.MongoClient("mongodb://root:!(%2FQqi%2B9ka0y@192.168.200.108:27017/?authSource=admin&replicaSet=rs0") # 
mydb = myclient["bms_pre"] # 数据库名
mycol = mydb["AccountBilling"] # 表名

#q1 = { "Code": "MX1290HNYVM7C" }
#x = mycol.find_one(q1)
#print(x)

now = datetime.datetime.now()

yesday = now + datetime.timedelta(days=-1)

yesdaystr = yesday.strftime('%Y-%m-%d')

print(yesdaystr)

query = { 'Code':'AR12FN9SFWG6C' } # 查询条件
sort = [('GenerationDate', 1)] #排序
c = 0
all_list = mycol.find(query).limit(10)
for item in all_list:    
    ## 账单信息
    for i in item["SettlmentItems"]:
        ## 结算项信息
        # 账单 + 结算项信息
        # 
        print(i)



        

